<template>
	<div>
		<el-input v-model="param.searchKey" placeholder="车牌号/sim卡号/组织机构" clearable size="mini"
			@keyup.enter.native="changeParam(param.searchKey,'kw')">
		</el-input>
		<el-select v-model="param.syxz" filterable clearable placeholder="车辆类型" style="margin-top: 10px;" size="mini"
			@change="(e) => changeParam(e, 'syxz')">
			<el-option label="道路货物运输" value="道路货物运输"></el-option>
			<el-option label="网络预约出租车" value="网络预约出租车"></el-option>
		</el-select>
		<div style="margin-top: 10px;">
			<label style="font-size: 14px;color: gray;">设备类型：</label>
			<el-radio-group v-model="param.videoType" @change="(e) => changeParam(e, 'video')">
				<el-radio label="0">全部</el-radio>
				<el-radio label="1">4G</el-radio>
				<el-radio label="2">2G</el-radio>
			</el-radio-group>

		</div>
		<div style="margin-top: 10px;">
			<label style="font-size: 14px;color: gray;">接入方式：</label>
			<el-radio-group v-model="param.connectType" @change="(e) => changeParam(e, 'connect')">
				<el-radio label="0">全部</el-radio>
				<el-radio label="1">直连</el-radio>
				<el-radio label="2">转发</el-radio>
			</el-radio-group>
		</div>
	</div>
</template>

<script>
	export default {
		name: 'searchContainer',
		data() {
			return {
				param: {
					videoType: '0',
					connectType: '0',
					searchType: 0,
					searchKey: null,
					syxz: null
				}

			}
		},
		methods: {
			isVehicleNumber(vehicleNumber) {
				var xreg =
					/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DF]$)|([DF][A-HJ-NP-Z0-9][0-9]{4}$))/;
				var creg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
				if (vehicleNumber.length == 7) {
					return creg.test(vehicleNumber);
				} else if (vehicleNumber.length == 8) {
					return xreg.test(vehicleNumber);
				} else {
					return false;
				}
			},
			changeParam(p, type) {
				if(type==='kw'){
					
					if(this.isVehicleNumber(p)){
						this.param.searchType=1
					}else if(/^\d+$/.test(p)){
						this.param.searchType=3
					}else if(p){
						this.param.searchType=2
					}else{
						this.param.searchType=0
					}
					
				}else if(type==='syxz'){
					if(p){
						this.param.searchType=4
					}else{
						this.param.searchType=0
					}
					
				}
				
				
				this.$emit('on-search',this.param)
			}
		}
	}
</script>

<style>
</style>